package com.example.qsindusty.jmm_spline.recombinationfragment;

import android.text.TextUtils;

import com.example.qsindusty.jmm_spline.OrdeFragment.OrderData;
import com.example.qsindusty.jmm_spline.api.ApiManager;
import com.yixin.ystartlibrary.base.BasePresenter;
import com.yixin.ystartlibrary.base.IBaseView;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Administration on 2018/4/8.
 */

public class RecombinationPresenter extends BasePresenter implements RecombinationContract.Presenter {
    RecombinationContract.View mView ;
    @Override
    public void bindView(IBaseView view) {
            mView= (RecombinationContract.View) view;
    }

    @Override
    public void unbindView() {
            dispose();
    }

    @Override
    public void getKeyOrder(String token,  String row, String page) {
        ApiManager.getInstence().getJmmApi().getKeyOrder(token,row,page)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<OrderData>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                    mView.showLoading();
                    }

                    @Override
                    public void onNext(OrderData jsonElement) {
                        if (TextUtils.equals(jsonElement.getStatus(),"0"))
                            if (jsonElement.getCount()!=0)
                            mView.getSuccessful(jsonElement);
                        else
                            mView.getNomore(jsonElement.getMessage());


                    }

                    @Override
                    public void onError(Throwable e) {
                    mView.closeLoading();
                        mView.getFraier(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        mView.closeLoading();
                    }
                });
    }


}
